package com.demo.exetion;


import com.demo.utils.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.nio.file.AccessDeniedException;

@RestControllerAdvice//全局异常处理总类
public class GlobalExceptionHandler {

    @ExceptionHandler(MainExection.class)
    public Result WoniuExection(MainExection e) {
        Result result = new Result();
        System.out.println(e.getCode());
        System.out.println(e.getMsg());
        result.fail(e.getCode(), e.getMsg(), null);
        return result;
    }

    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        System.out.println(e.getMessage());
        Result result = new Result();
        result.fail(500, "服务器繁忙", null);
        return result;
    }

    @ExceptionHandler(AccessDeniedException.class)
    public Result handleException(AccessDeniedException e) {
        System.out.println(e.getMessage());
        Result result = new Result();
        result.fail(500, e.getMessage(), null);
        return result;
    }
}
